/**
 * 
 */
package com.cipe.cmrs.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cipe.cmrs.model.Paymentrequestlineitem;

/**
 * @author Incepio
 * 
 */
@Service
@Transactional
public class PaymentrequestlineitemService extends BaseService<Paymentrequestlineitem> {
	public void deleteAll(Collection<Paymentrequestlineitem> items) {
		deleteAll(new HashSet<Paymentrequestlineitem>(items));
	}

    @Transactional(readOnly = true)
	public BigDecimal getProjectTotalAmount(Integer excludePaymentRequestId, Integer projectId) {
		List<String> conditions = new ArrayList<String>();
		List<Object> parameters = new ArrayList<Object>();
		if (projectId != null && excludePaymentRequestId != null) {
			conditions.add("paymentrequest.id != ?1");
			conditions.add("cipeproject.id = ?2");
			parameters.add(excludePaymentRequestId);
			parameters.add(projectId);
		} else if (projectId != null) {
			conditions.add("cipeproject.id = ?1");
			parameters.add(projectId);
		} else if (excludePaymentRequestId != null) {
			conditions.add("paymentrequest.id != ?1");
			parameters.add(excludePaymentRequestId);
		}

        conditions.add("paymentrequest.statusCode != ?" + (conditions.size() + 1));
        parameters.add(getText("status.payment.process.cancelled"));

        return dao.getSum(Paymentrequestlineitem.class, "paymentrequestamount", conditions, parameters);
    }

}
